package za.org.jcicada.genss.sensor.impl;

import za.org.jcicada.genss.sensor.ISensorValue;

/**
 * Concrete ISensorValue implementation.
 * @author rcrida
 */
public class SensorValue implements ISensorValue {

    /**
	 * The serial version ID
	 */
	private static final long serialVersionUID = 1L;

    /**
     * The timestamp associated with this value
     */
    private long time;
    
    /**
     * The actual value of the sensor
     */
    private Object value;
    
    /**
     * Construct object with all parameters specified.
     * @param time the desired timestamp
     * @param value the sensor metric value
     */
    public SensorValue(long time, Object value) {
        this.time = time;
        this.value = value;
    }
    
    /**
     * Construct object and fill in the current time
     * @param value the sensor metric value
     */
    public SensorValue(Object value) {
        this(System.currentTimeMillis(), value);
    }
    
    public long getTime() {
        return time;
    }

    public Object getValue() {
        return value;
    }
    
    @Override
    public boolean equals(Object aOther) {
        if (this == aOther)
            return true;
        if (!(aOther instanceof SensorValue)) 
            return false;
        SensorValue other = (SensorValue)aOther;
        if (!(value == null? other.value == null: value.equals(other.value)))
            return false;
        return time == other.time;
    }
    
    @Override
    public int hashCode() {
        return (int)time + (value == null? 0:value.hashCode());
    }
    
    @Override
    public String toString() {
    	return getValue().toString();
    }

}
